package com.bbcare.followup.plat.controller.fd;

import com.bbcare.comm.ResultModel;
import com.bbcare.followup.plat.dto.request.*;
import com.bbcare.followup.plat.dto.response.FuMilkPreparationRecordResDTO;
import com.bbcare.followup.plat.service.IFuMilkPreparationRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


/**
 * 备乳管理控制器
 *
 * @author liqianlong
 * @date 2021-04-21
 */
@RestController
@RequestMapping("milkPreparationRecord")
public class MilkPreparationRecordController {

    @Autowired
    private IFuMilkPreparationRecordService fuMilkPreparationRecordService;

    /**
     * PC端：待备乳管理--备乳录入列表。根据床号小号（在前面）到大号排序，未填写床号的排列在最前面（显示“未填写”），加床排列在最后面（带+号）。
     * @param reqDTO
     * @param request
     * @return
     */
    @PostMapping("/milkPrepPatientPage")
    public ResultModel milkPrepPatientPage(@RequestBody MilkPreparationRecordUserPageReqDTO reqDTO, HttpServletRequest request) throws Exception {
        Map<String,Object> map = fuMilkPreparationRecordService.milkPrepPatientPageWithCount(reqDTO,request);
        return new ResultModel(map);
    }

    /**
     * 设置备乳量
     * @param reqDTO
     * @param request
     * @return
     */
    @PostMapping("/setMilkQuantity")
    public synchronized ResultModel setMilkQuantity(@RequestBody MilkPreparationSetReqDTO reqDTO, HttpServletRequest request) {
        String id = fuMilkPreparationRecordService.setMilkQuantity(reqDTO,request);
        return new ResultModel(id);
    }

    /**
     * 发送备乳通知,备乳发送历史-详情
     * @param reqDTO
     * @param request
     * @return
     */
    @PostMapping("/listPage")
    public ResultModel listPage(@RequestBody MilkPreparationRecordPageReqDTO reqDTO, HttpServletRequest request) {
        Map<String,Object> map = fuMilkPreparationRecordService.listPage(reqDTO,request);
        return new ResultModel(map);
    }

    /**
     * 备乳发送历史
     * @param reqDTO
     * @param request
     * @return
     */
    @PostMapping("/sendHistoryPage")
    public ResultModel sendHistoryPage(@RequestBody MilkPreparationHistoryPageReqDTO reqDTO, HttpServletRequest request) {
        Map<String,Object> map = fuMilkPreparationRecordService.sendHistoryPage(reqDTO,request);
        return new ResultModel(map);
    }



    /**
     * 批量发送通知
     * @param reqDTO
     * @param request
     * @return
     */
    @PostMapping("/confirmSend")
    public ResultModel confirmSend(@RequestBody MilkPreparationChoiceReqDTO reqDTO, HttpServletRequest request) throws Exception {
        fuMilkPreparationRecordService.confirmSend(reqDTO,request);
        return new ResultModel("发送成功");
    }

    /**
     * 备乳详情
     * @param id 主键ID
     * @return
     */
    @GetMapping("/detail/{id}")
    public ResultModel selectOne(@PathVariable("id") String id) {
        FuMilkPreparationRecordResDTO resDTO = fuMilkPreparationRecordService.selectOne(id);
        return new ResultModel(resDTO);
    }

    @PostMapping("/delete/{id}")
    public ResultModel delete(@PathVariable("id") final String id) {
        final int delRet    = fuMilkPreparationRecordService.deleteByPK(id);
        if (1 == delRet) {
            return new ResultModel("删除已成功。");
        } else {
            return new ResultModel("删除失败！！");
        }
    }
}
